package com.sky.utils;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Slf4j
public class ResponseUtil {
    public static void writeErrorResponse(HttpServletResponse response, int status, String message) {
        response.setStatus(status);
        response.setContentType("application/json;charset=UTF-8");
        try {
            PrintWriter writer = response.getWriter();
            writer.write(String.format("{\"code\": %d, \"message\": \"%s\"}", status, message));
            writer.flush();
            writer.close();
        } catch (IOException e) {
            log.error("响应写入失败：{}", e.getMessage());
        }
    }
}
